package com.dongdongshop.controller;

import com.dongdongshop.data.Result;
import com.dongdongshop.service.SellerService;
import com.dongdongshop.vo.SellerVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("seller")
public class SellerController {
    @Autowired
    private SellerService sellerService;

    //通过id查询商家
    @PostMapping("getSellerByName")
    public Result getSellerByName(@RequestParam String sellerId) {
        SellerVO sellerVO = sellerService.getSellerByName(sellerId);
        return Result.OK().setData(sellerVO);
    }

    //注册商家
    @PostMapping("registerSeller")
    public Result registerSeller(@RequestBody SellerVO sellerVO) {
        int i = sellerService.registerSeller(sellerVO);
        if (i >= 1) {
            return Result.OK();
        }
        return Result.FAIL();
    }

    //查询所有商家
    @PostMapping("getAllSeller")
    public Result getAllSeller() {
        List<SellerVO> sellerVOList = sellerService.getAllSeller();
        return Result.OK().setData(sellerVOList);
    }

    //查询商家
    @GetMapping("getSellerById")
    public Result getSellerById(@RequestParam String sellerId) {
        SellerVO sellerVO = sellerService.getSellerById(sellerId);
        return Result.OK().setData(sellerVO);
    }

    //修改状态
    @PostMapping("updateSellerById")
    public Result updateSellerById(@RequestParam String sellerId) {
        sellerService.updateSellerById(sellerId);
        return Result.OK();
    }

}
